//
//  BookDetailHeaderView.m
//  Cunli
//
//  Created by lilubin on 15/7/7.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "BookDetailHeaderView.h"
#import "UIImageView+WebCache.h"
#import "BookDetailModel.h"
#import "UIColor+expanded.h"

@implementation BookDetailHeaderView
{
    NSUInteger _currentIndex;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
//    UIImage *btnBgImg = [UIImage imageNamed:@"btn_login_login.png"];
//    btnBgImg = [btnBgImg stretchableImageWithLeftCapWidth:5 topCapHeight:0];
//    [_addStudyBtn setBackgroundImage:btnBgImg forState:UIControlStateNormal];
//    [_readBtn setBackgroundImage:btnBgImg forState:UIControlStateNormal];
    UIColor *btnBgColor = [UIColor colorWithHexString:@"0x2fa9f4"];
    [_addStudyBtn setBackgroundColor:btnBgColor];
    [_readBtn setBackgroundColor:btnBgColor];
    
    NSURL *imgURL = [NSURL URLWithString:_detailModel.pic];
    [_titleImgView setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"default_news"]];
    _titleLabel.text = _detailModel.title;
    if (_detailModel.pressinfo != nil) {
        _authorLabel.text = [NSString stringWithFormat:@"作者:%@", _detailModel.pressinfo];
    }
    else
    {
        _authorLabel.text = @"作者:";
    }
    _readNumLabel.text = [NSString stringWithFormat:@"阅读:%@", _detailModel.hits];
    UIColor *textColor = [UIColor colorWithHexString:@"0x777777"];
    [_authorLabel setTextColor:textColor];
    [_readNumLabel setTextColor:textColor];
    
    _addStudyBtn.tag = 101;
    [_addStudyBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    _readBtn.tag = 102;
    [_readBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self setBackgroundColor:[UIColor colorWithHexString:@"0xf6f6f6"]];
    UIColor *bgColor = [UIColor colorWithHexString:UIBgColorValue];
    [_titleLabel setBackgroundColor:bgColor];
    [_authorLabel setBackgroundColor:bgColor];
    [_readNumLabel setBackgroundColor:bgColor];
    [self setBackgroundColor:bgColor];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)btnAction:(UIButton *)button
{
        _buttonClicked(button.tag-100);
}

@end
